package com.example.gitproject.Boom;


import java.util.Random;
import java.util.Scanner;

public class Boom {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        // 生成一个1到100之间的随机数
        int numberToGuess = random.nextInt(100) + 1;
        int numberOfTries = 0;
        int guess;
        boolean hasGuessedCorrectly = false;

        // 初始化高低区间
        int low = 1;
        int high = 100;

        System.out.println("欢迎来到点数炸弹游戏！");
        System.out.println("我已经生成了一个1到100之间的随机数。试着猜猜看吧！");

        // 用户猜测循环
        while (!hasGuessedCorrectly) {
            System.out.println("当前猜测范围是：" + low + " 到 " + high);
            System.out.print("请输入你的猜测：");
            guess = scanner.nextInt();
            numberOfTries++;

            if (guess < low || guess > high) {
                System.out.println("你的输入超出了范围，请输入 " + low + " 到 " + high + " 之间的数字。");
            } else if (guess < numberToGuess) {
                System.out.println("你的猜测太低了。");
                low = guess + 1; // 更新低区间
            } else if (guess > numberToGuess) {
                System.out.println("你的猜测太高了。");
                high = guess - 1; // 更新高区间
            } else {
                hasGuessedCorrectly = true;
                System.out.println("恭喜你！你猜对了！");
                System.out.println("你一共猜了 " + numberOfTries + " 次。");
            }
        }

        scanner.close();
    }
}